﻿@model IEnumerable<BabyShop.Site.Models.Product>

@{
    ViewBag.IsFormIndex = true;
    ViewBag.Title = "Product Management";
}
@section FooterScript{
    <script type="text/javascript">
        $(function () {
            $.jqgrid.getCurr().jqGrid({
                url: '@Url.Action("ProductList")',
                datatype: "json",
                mtype: 'post',
                colNames: ['KeyGuid', '商品名称', '商品类型', '价格', '更新时间', '是否删除'],
                colModel: [
                        { name: 'KeyGuid', index: 'ProductGuid', width: 90, editable: false, hidden: true },
                        { name: '功能名', index: 'ProductName', width: 90, editable: true },
                        { name: '商品类型', index: 'ProductType.ProductTypeName', width: 90, editable: true },
                        { name: '价格', index: 'Price', width: 90, editable: true },
                        { name: '更新时间', index: 'CommonColumns.LastModified', formatter: 'date',
                            formatoptions: { newformat: 'Y/m/d' }, width: 80, align: 'center', editable: true
                        },
                        { name: '是否删除', index: 'CommonColumns.IsDelete', width: 80, align: 'center',
                            editable: true, edittype: 'checkbox', editoptions: { value: '是:否' }
                        }
                    ],
                rowNum: 10,
                rowList: [10, 20, 30],
                pager: '#jqGridPager',
                sortname: "CommonColumns.LastModified",
                viewrecords: true,
                hidegrid: false,
                rownumbers: true,
                sortorder: "desc",
                caption: '@ViewBag.Title',
                height: '100%',
                width: '100%',
                ondblClickRow: EditEntry
            });

            var iframeSize = $.bs.getContainerWidthAndHeight($.removePrefix($.sysRes.iframeName), false);
            $.jqgrid.getCurr().jqGrid('navGrid', '#jqGridPager', { add: false, edit: false, del: false, search: false })
                .navButtonAdd('#jqGridPager', {
                    caption: "删除",
                    buttonicon: "ui-icon-del",
                    onClickButton: function () {
                        var id = $.jqgrid.getCurr().getGridParam("selrow");
                        if (id == null) {
                            alert("请选择行！");
                            return;
                        }
                        DeleteEntry(id);
                    }
                }).setGridWidth(iframeSize.width);

            $(".searchTable>tbody>tr>td:has(label)").addClass("evenTD");
        });

        function EditEntry(id) {
            if (id == "newId")
                return;
            else {
                var keyGuid = $.jqgrid.getCurr().getCell(id, "KeyGuid");
                $.bs.loadInContainer('@Url.Action("Edit")?keyGuid=' + keyGuid);
                //$.bs.showDialog({ url: '@Url.Action("Edit")?keyGuid=' + keyGuid, title: '修改功能描述' });
            }
        }

        function DeleteEntry(rowId) {
            if (rowId != 'newId') {
                var keyGuid = $.jqgrid.getCurr().getCell(rowId, 'KeyGuid');
                $.ajax({
                    url: '@Url.Action("Remove")',
                    type: 'post',
                    dataType: 'json',
                    data: { keyGuid: keyGuid },
                    success: function (result) {
                        if (result.ErrorCode == 0)
                            $.bs.showMsg('提示信息', result.ShowMsg);
                        else
                            $.bs.showErr('出错啦', result.ShowMsg);
                    }
                });
            }
            return;
        }
    </script>
}
<fieldset class="ui-corner-all">
    <legend>查询</legend>
    <table class="searchTable">
        <tr>
            <td><label>商品名称</label></td>
            <td>
                <input type="text" id="txtProductName" autofocus="true"
                 placeholder="商品名称" 
                 data-searchField="ProductName" data-searchOp="cn" />
            </td>
            <td><label>商品类型</label></td>
            <td>
                @Html.DropDownList("slProductType", ViewBag.ProductTypeList as IEnumerable<SelectListItem>, "全部",
                         new ViewDataDictionary { 
                             new KeyValuePair<string, object>("data-searchField","ProductTypeGuid"),
                             new KeyValuePair<string, object>("data-searchOp","eq")
                         })
            </td>
            <td>
                <input type="button" id="btnSearch" class="ui-button ui-jqgrid-search" value="查询" />
                @Html.ActionLink("添加商品", "Create", null, new { id = "lkCreate", @class = "ui-button" })
            </td>
        </tr>
    </table>
</fieldset>
<table id="jqGridTable" class="ui-jqgrid-btable"></table>
<nav id="jqGridPager" class="ui-jqgrid-pager"></nav>
